package com.rescue.mapper;

import com.rescue.forum.entity.LikeRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface LikeRecordMapper {
    @Select("select * from like_record where comment_id = #{commentId} and user_id = #{userId}")
    List<LikeRecord> getByCommentIdAndUserId(Integer commentId, Integer userId);

    @Select("select * from like_record where article_id = #{articleId} and user_id = #{userId}")
    List<LikeRecord> getByArticleIdAndUserId(String articleId, Integer userId);

    @Insert("insert into like_record (op_type, article_id,comment_id, user_id, create_time, author_user_id) VALUE (#{opType}, #{articleId},#{commentId}, #{userId}, #{createTime}, #{authorUserId})")
    void save(LikeRecord likeRecord);

    void delete(List<LikeRecord> likeRecords);

    @Select("select count(*) from like_record where user_id = #{userId} and date (create_time) = #{date}")
    Integer getLikeCount(LocalDate date, Integer userId);

    @Select("select count(*) from  like_record lr join forum_comment fc on lr.comment_id = fc.comment_id where fc.user_id = #{userId}")
    Integer getBALikeTimesById(Integer userId);

    @Select("select count(*) from  like_record lr join forum_article fa on lr.article_id = fa.article_id where fa.user_id = #{userId}")
    Integer getBCLikeTimesById(Integer userId);
}
